<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>
    <header class="header header-f" style="padding-top:2rem; height:4rem;">
        <div class="header-l aui-pull-left" onclick="closeWin()">
            <i class="fa fa-angle-left"></i>
        </div>
            <form class="search" action="javascript:search()">
        <div class="search">
            <label>
            <span class="aui-iconfont aui-icon-search"></span>
            <input type="text" placeholder="请输入商品名称" id='searchText'>
        </label>
        </div>
        <div class="header-r aui-pull-right" onclick="search()">
            <i class="fa fa-shopping-cart"></i>
        </div>
      </form>

    </header>
    <div style="height:4rem;"></div>


    <div id="list">

    </div>


    <script type="text/template" id="template">
        <div class="index-goods">
            <ul>
                {{~it.result.data:value:index}}
                <li onclick="buy_detail({{=value.mall_id}})">
                    <img src="{{=value.image}}">
                    <dl>
                        <dt>{{=value.title}}</dt>
                        <dd>￥{{=value.market_price}}<span>立即够买</span></dd>
                    </dl>
                </li>
                {{~}}
            </ul>
        </div>
    </script>

</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript">
    apiready = function() {

        // getData();
    }

    function search() {
        var text = $('input').val();
        getData(text);

    }


    function getData(text) {

        api.ajax({
            url: webAddress + '/a/mall/List/index',
            method: 'get',
            data: {
                values: {
                    limit: 50,
                    keyword: text
                },
            },
            headers: {
                TOKEN: token
            }
        }, function(ret, err) {
            if (ret) {
                //  console.log(JSON.stringify(ret));

                var template = $api.byId('template');
                var dotFn = doT.template(template.innerHTML);
                var html = dotFn(ret);
                var list = $api.byId('list');
                $api.html(list, html);
            } else {
                // alert(JSON.stringify(err));
                api.toast({
                    msg: err.body.message,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });

    }

    function buy_detail(index) {
        api.openWin({
            name: 'goods_details',
            url: './goods_details.html',
            pageParam: {
                id: index
            }
        });
    }




    function openClub() {
        var delay = 0;
        if (api.systemType != 'ios') {
            delay = 300;
        }
        api.openWin({
            name: 'club_win',
            url: './html/club_win.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    }



    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
